package com.migo3.sso.pojo.generated;

import com.migo3.sso.pojo.User;
import com.migo3.sso.pojo.UserImpl;
import com.speedment.common.injector.annotation.ExecuteBefore;
import com.speedment.runtime.config.identifier.TableIdentifier;
import com.speedment.runtime.core.component.sql.SqlPersistenceComponent;
import com.speedment.runtime.core.component.sql.SqlStreamSupplierComponent;
import com.speedment.runtime.core.exception.SpeedmentException;

import javax.annotation.Generated;
import java.sql.ResultSet;
import java.sql.SQLException;

import static com.speedment.common.injector.State.RESOLVED;
import static com.speedment.runtime.core.internal.util.sql.ResultSetUtil.getString;

/**
 * The generated Sql Adapter for a {@link User} entity.
 * <p>
 * This file has been automatically generated by Speedment. Any changes made to
 * it will be overwritten.
 * 
 * @author Speedment
 */
@Generated("Speedment")
public abstract class GeneratedUserSqlAdapter {
    
    private final TableIdentifier<User> tableIdentifier;
    
    protected GeneratedUserSqlAdapter() {
        this.tableIdentifier = TableIdentifier.of("db0", "migo2", "tb_user");
    }
    
    @ExecuteBefore(RESOLVED)
    void installMethodName(SqlStreamSupplierComponent streamSupplierComponent, SqlPersistenceComponent persistenceComponent) {
        streamSupplierComponent.install(tableIdentifier, this::apply);
        persistenceComponent.install(tableIdentifier);
    }
    
    protected User apply(ResultSet resultSet) throws SpeedmentException{
        final User entity = createEntity();
        try {
            entity.setId(resultSet.getLong(1));
            entity.setUsername(resultSet.getString(2));
            entity.setPassword(resultSet.getString(3));
            entity.setPhone(getString(resultSet, 4));
            entity.setEmail(getString(resultSet, 5));
            entity.setCreated(resultSet.getTimestamp(6));
            entity.setUpdated(resultSet.getTimestamp(7));
        } catch (final SQLException sqle) {
            throw new SpeedmentException(sqle);
        }
        return entity;
    }
    
    protected UserImpl createEntity() {
        return new UserImpl();
    }
}